package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.mapper.OrderMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangyu
 * @data 2023/4/25 14:08
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "商家操作订单相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("商家搜索订单接口")
    public Result<PageResult> selectOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("分页查询条件: {}", ordersPageQueryDTO);
        return Result.success(orderService.selectOrders(ordersPageQueryDTO));
    }

    @GetMapping("/statistics")
    @ApiOperation("商家统计各个状态的订单")
    public Result<OrderStatisticsVO> getOrderStatus() {
        return Result.success(orderService.getOrderStatus());
    }

    @GetMapping("/details/{id}")
    @ApiOperation("商家查看订单详情")
    public Result<OrderVO> selectOrderDetails(@PathVariable Long id) {
        return Result.success(orderService.selectOrderDetails(id));
    }

    @PutMapping("/confirm")
    @ApiOperation("商家接单接口")
    public Result<String> confirmOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("idss: {}", ordersRejectionDTO.getId());
        orderService.confirmOrder(ordersRejectionDTO.getId());
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("商家拒单接口")
    public Result<String> rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("商家取消订单")
    public Result<String> cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("商家派送订单")
    public Result<String> Delivery(@PathVariable Long id) {
        orderService.Delivery(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("商家完成订单接口")
    public Result<String> complete(@PathVariable Long id) {
        orderService.complete(id);
        return Result.success();
    }


}
